package com.minelx.sequence.core;

import java.util.List;

import static java.util.stream.Collectors.toList;

public class RepeatMatcher<E> implements ReturnMatcher<List<E>, StringScanner> {

	private final ReturnMatcher<E, StringScanner> repeating;

	public RepeatMatcher(ReturnMatcher<E, StringScanner> repeating) {
		this.repeating = repeating;
	}

	@Override
	public boolean isMatch(StringScanner clue) {
		return repeating.isMatch(clue);
	}

	@Override
	public List<E> onMatched(StringScanner clue) {
		return clue.stream(repeating).collect(toList());
	}
}
